<?php
namespace ctrl\demo;


use Sdk\Yqn\callYqnApiUtil;

class yqn
{
    //获取仓库列表 http://ec.com/?c=demo_yqn&a=warehouseList
    public static function warehouseList()
    {
        $action = '/v1/warehouse/findAll';
        $data = [];
        $result = callYqnApiUtil::callYqnApi($action, 'GET', $data);
        if (!empty($result)) {
            $star = 184;
            foreach ($result['data'] as $k => $v) {
                $id = $star + $k;
                $warehouseName = addslashes($v['name']);
                $address = $v['address1'].$v['address2'];
                $sql = "INSERT INTO warehouse(warehouse_id, `name`, `name_en`, warehouse_code, country, province, city, address, postcode) 
                        VALUES ('{$id}', '{$warehouseName}', '{$warehouseName}', '{$v['warehouseCode']}', '{$v['country']}', '{$v['state']}', '{$v['city']}', '{$address}', '{$v['postal']}');";
                echo $sql;
                echo '<br />';
            }
        }
    }

    //运去哪 http://ec.com/?c=demo_yqn&a=pull
    public static function pull()
    {
        \serv\task\warehouse\yqn::pull();
    }

    //运去哪 http://ec.com/?c=demo_yqn&a=pullQueue
    public static function pullQueue()
    {
        $string = '{"warehouse_id":"186","warehouse_code":"NJB"}';
        $data['data'] = json_decode($string, true);
        $result = \serv\queue\warehouse\yqn::pull($data);
        var_dump($result);
    }

    //http://ec.com/?c=demo_yqn&a=stock
    public static function stock()
    {
        $string = '{"warehouse_code":"NJB","product_line_name":"储物柜","sku":"A0022008-W-1","inventory_type":1,"inventory_available":0,"inventory_reserved":0,"inventory_transport":1,"inventory_current":0,"updated_at":"2024-03-18 04:05:00","warehouse_id":"186"}';
        $data['data'] = json_decode($string, true);
        $result = \serv\queue\warehouse\yqn::check($data);
        var_dump($result);
    }

}


